home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
music
/
eked-m1.zoo
/
src
/
comb_ed.c
next >
Wrap
C/C++ Source or Header
|
1995-02-19
|
8KB
|
280 lines
/*
* EKED-M1 : Editor for Korg M1 synth; comb_ed.c : combination editor
* Copyright (C) 1995 Steven M. Eker (Steven.Eker@brunel.ac.uk)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stddef.h>
#include <string.h>
#include <gemfast.h>
#include <aesbind.h>
#include "gm/gem_man.h"
#include "eked-m1.h"
#include "defs.h"
#include "types.h"
#include "externs.h"
typedef struct {
int offset;
PARA_TYPE type;
int page;
} CPARAMETER;
CPARAMETER comb_table[] =
{
{0, PROG, 1},
{10, CHAN, 2},
{6, NOTE, 4},
{5, NOTE, 3},
{8, VEL, 6},
{7, VEL, 5},
{1, UNUM, 7},
{2, SN12, 8},
{3, SN50, 9},
{4, CPAN, 10},
{9, DIS0, 11},
{9, DIS1, 12},
{9, DIS2, 13},
{9, DIS3, 14}
};
static OBJECT *combination;
static OBJECT *effect_route;
static OBJECT *effect1;
static OBJECT *effect2;
static BANK *edit_bank;
static int number;
static int in_use;
static BYTE data[COMBINATION_SIZE];
static BYTE compare[COMBINATION_SIZE];
static void comb_setup();
static void display(int x_pos, int y_pos, GRECT *clip, long usr_val);
static int action(int handle, E_TYPE type, void *event,
int x_pos, int y_pos, long usr_val);
static void save_comb(BYTE *p);
static void do_click(int handle, int m_x, int m_y);
static void setup(int x_pos, int y_pos);
static void comb_edit(int handle, int m_x, int m_y);
static void comb_buttons(int handle, int ob);
void ce_window(BANK *bank, int nr)
{
static char title[] = "Edit Bank 0 Combination 00";
int t;
if(in_use){
fm_alert(1, COMB_ED_ALERT);
return;
}
rm_gaddr(R_TREE, COMBINATION, &combination);
rm_gaddr(R_TREE, EFFECT_ROUTE_C, &effect_route);
rm_gaddr(R_TREE, EFFECT1_C, &effect1);
rm_gaddr(R_TREE, EFFECT2_C, &effect2);
edit_bank = bank;
number = nr;
memcpy(data, COMB_DATA(bank, nr), (size_t) COMBINATION_SIZE);
comb_setup();
combination[C_COMPARE].ob_state &= ~SELECTED;
combination[C_RESET].ob_state &= ~DISABLED;
combination[C_SAVE].ob_state &= ~DISABLED;
title[10] = '0' + bank->bank_nr;
title[sizeof(title) - 3] = '0' + nr / 10;
title[sizeof(title) - 2] = '0' + nr % 10;
t = wm_open(NAME | CLOSER | FULLER | MOVER | SIZER |
UPARROW | DNARROW | VSLIDE |
LFARROW | RTARROW | HSLIDE,
(GRECT *) 0, title, combination[0].ob_width,
combination[0].ob_height + effect_route[0].ob_height +
effect1[0].ob_height, char_w, char_h, &display, &action, 0L);
if(t < 0){
fm_alert(1, WINDOW_ALERT);
return;
}
in_use = TRUE;
}
static void comb_setup()
{
OBJECT *c;
BYTE *p;
int i, j;
para_fill(combination + C_NAME, NM10, data);
c = combination + C_TIMBRE1 + 1;
for(i = 0, p = data + 36; i <= 7; i++, p += 11, c++){
for(j = 0; j < 14; j++, c++)
para_fill(c, comb_table[j].type, p + comb_table[j].offset);
}
eroute_setup(effect_route, data + 11);
epara_setup(effect1, 0, data + 11);
epara_setup(effect2, 1, data + 11);
}
static void display(int x_pos, int y_pos, GRECT *clip, long usr_val)
{
setup(x_pos, y_pos);
objc_draw(combination, 0, MAX_DEPTH, clip->g_x, clip->g_y,
clip->g_w, clip->g_h);
objc_draw(effect_route, 0, MAX_DEPTH, clip->g_x, clip->g_y, clip->g_w,
clip->g_h);
objc_draw(effect1, 0, MAX_DEPTH, clip->g_x, clip->g_y, clip->g_w, clip->g_h);
objc_draw(effect2, 0, MAX_DEPTH, clip->g_x, clip->g_y, clip->g_w, clip->g_h);
}
static int action(int handle, E_TYPE type, void *event,
int x_pos, int y_pos, long usr_val)
{
BYTE *p;
switch(type){
case E_CLEANUP:
m1_ctrl(handle, EXITING, 0, 0, (BYTE *) NULL);
in_use = FALSE;
break;
case E_MESSAGE:
if(((int *) event)[0] == WM_CLOSED){
p = (combination[C_COMPARE].ob_state & SELECTED) ? compare : data;
if(memcmp(p, COMB_DATA(edit_bank, number),
(size_t) COMBINATION_SIZE) != 0){
switch(fm_alert(1, COMB_QUIT_ALERT)){
case 1: /* save */
save_comb(p);
break;
case 3: /* cancel */
return R_NOACT;
}
}
}
break;
case E_CLICK:
m1_ctrl(handle, 0, EDIT_COMB_MODE, number, data);
setup(x_pos, y_pos);
do_click(handle, ((CLICK *) event)->m_x, ((CLICK *) event)->m_y);
break;
}
return R_NORMAL;
}
static void save_comb(BYTE *p)
{
static int msg[] = {UPDATE_ITEM, 0};
memcpy(COMB_DATA(edit_bank, number), p, (size_t) COMBINATION_SIZE);
if(edit_bank->comb_win != 0){
msg[1] = number;
wm_send_user(edit_bank->comb_win, (long) &msg);
}
}
static void do_click(int handle, int m_x, int m_y)
{
if(m_y < effect_route[0].ob_y)
comb_edit(handle, m_x, m_y);
else if(m_y < effect1[0].ob_y)
eroute_edit(handle, effect_route, 15, m_x, m_y, data + 11);
else if(m_x < effect2[0].ob_y)
effect_edit(handle, effect1, 0, 15, m_x, m_y, data + 11);
else
effect_edit(handle, effect2, 1, 15, m_x, m_y, data + 11);
}
static void setup(int x_pos, int y_pos)
{
int y1 = y_pos + combination[0].ob_height;
int y2 = y1 + effect_route[0].ob_height;
combination[0].ob_x = x_pos;
combination[0].ob_y = y_pos;
effect_route[0].ob_x = x_pos;
effect_route[0].ob_y = y1;
effect1[0].ob_x = x_pos;
effect1[0].ob_y = y2;
effect2[0].ob_x = x_pos + effect1[0].ob_width;
effect2[0].ob_y = y2;
}
static void comb_edit(int handle, int m_x, int m_y)
{
int ob = objc_find(combination, 0, MAX_DEPTH, m_x, m_y);
int i, t;
if(ob == C_NAME)
para_edit(handle, combination, ob, NM10, -1, -1, data);
else if(ob > C_TIMBRE1){
i = (ob - C_TIMBRE1 - 1) % 15;
t = (ob - C_TIMBRE1 - 1) / 15;
if(i <= 13 && t <= 7){
para_edit(handle, combination, ob, comb_table[i].type,
comb_table[i].page, t + 8,
data + 36 + 11 * t + comb_table[i].offset);
}
}
else
comb_buttons(handle, ob);
}
static void comb_buttons(int handle, int ob)
{
switch(ob){
case C_COMPARE:
if(!wm_do_button(handle, combination, ob, TRUE))
return;
if(combination[C_COMPARE].ob_state & SELECTED){
memcpy(compare, data, (size_t) COMBINATION_SIZE);
memcpy(data, COMB_DATA(edit_bank, number), (size_t) COMBINATION_SIZE);
}
else
memcpy(data, compare, (size_t) COMBINATION_SIZE);
combination[C_RESET].ob_state ^= DISABLED;
combination[C_SAVE].ob_state ^= DISABLED;
break;
case C_RESET:
if(!wm_do_button(handle, combination, ob, FALSE))
return;
memcpy(data, COMB_DATA(edit_bank, number), (size_t) COMBINATION_SIZE);
break;
case C_SAVE:
if(wm_do_button(handle, combination, ob, FALSE))
save_comb(data);
return;
default:
return;
}
tx_comb_dmp(data);
comb_setup();
wm_update(handle);
}
void prog_update(OBJECT *object, int value)
{
char *string = TEXT_PTR(object, 0);
if(value == -1){
(void) strcpy(string, "OFF ");
return;
}
if(value < 100)
(void) korg2str(string, PROG_DATA(edit_bank, value), (size_t) 10);
else{
value -= 100;
(void) strcpy(string, "Card ");
string[5] = '0' + value / 10;
string[6] = '0' + value % 10;
}
}